package com.zhongshengnetwork.rightbe.lang.activity;

import android.app.Activity;
//import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
//import android.databinding.DataBindingUtil;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
//import android.support.annotation.NonNull;
//import android.support.v4.app.FragmentActivity;
//import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.pj.core.utilities.ConvertUtility;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.BezierRadarHeader;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.tencent.connect.common.Constants;
import com.tencent.connect.share.QQShare;
import com.tencent.connect.share.QzoneShare;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXTextObject;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;
import com.wang.avi.AVLoadingIndicatorView;
import com.zhongshengnetwork.rightbe.Constant.APIKey;
import com.zhongshengnetwork.rightbe.CustomApplication;
import com.zhongshengnetwork.rightbe.R;
import com.zhongshengnetwork.rightbe.bindings.CommonItemBinding;
import com.zhongshengnetwork.rightbe.bindings.CommonReplyBinding;
import com.zhongshengnetwork.rightbe.common.AppThemeUtils;
import com.zhongshengnetwork.rightbe.common.BroadcastDefine;
import com.zhongshengnetwork.rightbe.common.CircleTransform;
import com.zhongshengnetwork.rightbe.common.CommonUtils;
import com.zhongshengnetwork.rightbe.common.DateUtil;
import com.zhongshengnetwork.rightbe.common.GsonTools;
import com.zhongshengnetwork.rightbe.common.ScreenUtils;
import com.zhongshengnetwork.rightbe.common.TopBarView;
import com.zhongshengnetwork.rightbe.common.activity.AppBaseActivity;
import com.zhongshengnetwork.rightbe.common.activity.ReportActivity;
import com.zhongshengnetwork.rightbe.common.customview.ActionSheetDialog;
import com.zhongshengnetwork.rightbe.common.customview.CustomDialog;
import com.zhongshengnetwork.rightbe.common.customview.KeyMapDailog;
import com.zhongshengnetwork.rightbe.common.customview.MyListView;
import com.zhongshengnetwork.rightbe.common.customview.SelfListView;
import com.zhongshengnetwork.rightbe.common.customview.ShareDialog;
import com.zhongshengnetwork.rightbe.common.pulluprefresh.xlistview.XListView;
import com.zhongshengnetwork.rightbe.common.utils.ToastUtil;
import com.zhongshengnetwork.rightbe.gsonmodel.CommonModel;
import com.zhongshengnetwork.rightbe.gsonmodel.DryCommentModel;
import com.zhongshengnetwork.rightbe.gsonmodel.LangInfoModel;
import com.zhongshengnetwork.rightbe.gsonmodel.WeiShuContentDetailModel;
import com.zhongshengnetwork.rightbe.gsonmodel.WeiShuInfoDetailModel;
import com.zhongshengnetwork.rightbe.https.HttpCallBack;
import com.zhongshengnetwork.rightbe.https.HttpsUtils;
import com.zhongshengnetwork.rightbe.login.LoginActivity;
import com.zhongshengnetwork.rightbe.view.controller.CommonItemViewController;
import com.zhongshengnetwork.rightbe.wzt.activity.WZTActivity;
import com.zhongshengnetwork.rightbe.wzt.activity.WZTContentActivity;
import com.zhongshengnetwork.rightbe.wzt.model.WZTUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LangCommentActivity extends AppBaseActivity implements TopBarView.onTitleBarClickListener{

    private CommonReplyBinding rootBinding;

    private TopBarView topbar;
    private DryCommentModel dryCommentModel;
    private String id;
    private String uid;
    private String commentId;
    private String replyContent;
    private String replyName;
    private int type = 0;
    private int way = 1;

    private Button comment_reply_bt;

    private static final int Records = 20;
    private int pageIndex = 0;
    private List<DryCommentModel> list=null;
    private RecyclerView listview;
    private CommentRecyclerAdapter adapter;

    //评论弹出框
    private KeyMapDailog dialog = null;
    private DryCommentModel replyCommentModel = null;

    //加载动画
    private AVLoadingIndicatorView avi;
    private boolean isReply = false;
    private boolean isShare = false;

    private int opIndex = 0;
    //微信分享
    private List<String> nameList;
    private List<String> moreList;

    private ScrollView myScrollView;

    private ClipboardManager myClipboard;

    private RefreshLayout mRefreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        rootBinding = DataBindingUtil.setContentView(this, R.layout.activity_lang_comment);

        RelativeLayout lang_comment_layout = (RelativeLayout) rootBinding.langCommentLayout;
        lang_comment_layout.setBackgroundColor(AppThemeUtils.getInstance().getMainColor());
        RelativeLayout comment_reply_layout = (RelativeLayout) rootBinding.commentReplyLayout;
        comment_reply_layout.setBackgroundColor(AppThemeUtils.getInstance().getMainColor());
        LinearLayout comment_reply_line = (LinearLayout) rootBinding.commentReplyLine;
        comment_reply_line.setBackgroundColor(AppThemeUtils.getInstance().getBackgroundColor());
        LinearLayout comment_left = (LinearLayout) rootBinding.commentLeft;
        comment_left.setBackgroundColor(AppThemeUtils.getInstance().getBackgroundColor());
        LinearLayout comment_right = (LinearLayout) rootBinding.commentRight;
        comment_right.setBackgroundColor(AppThemeUtils.getInstance().getBackgroundColor());
        Button comment_reply_bt = (Button) findViewById(R.id.comment_reply_bt);
        comment_reply_bt.setBackgroundColor(AppThemeUtils.getInstance().getBackgroundColor());

        LinearLayout comment_bg = (LinearLayout) rootBinding.commentBg;
        comment_bg.setBackgroundColor(AppThemeUtils.getInstance().getMainColor());

        id = getIntent().getStringExtra(APIKey.idKey);
        dryCommentModel = (DryCommentModel) getIntent().getSerializableExtra("DryCommentModel");
        if (CommonUtils.isEmpty(id)){
            id = dryCommentModel.getSourceid();
        }
        int count = Integer.valueOf(dryCommentModel.getCcount()) - dryCommentModel.getReplycount();
        dryCommentModel.setCcount(count+"");
        replyCommentModel = dryCommentModel;
        isReply = getIntent().getBooleanExtra("isReply",false);
        isShare = getIntent().getBooleanExtra("isShare",false);
        type = getIntent().getIntExtra(APIKey.typeKey,0);
        way = getIntent().getIntExtra("way", 1);
        if (dryCommentModel.getOrderid() > 0){
            way = 0;
        }
        uid = dryCommentModel.getUserid();
        commentId = dryCommentModel.getCommentid();

        myScrollView = (ScrollView) findViewById(R.id.myScrollView);

        topbar = rootBinding.topbar;
        topbar.getRightView().setVisibility(View.GONE);
        topbar.setClickListener(this);
        topbar.getTitleView().setClickable(true);
        topbar.getTitleView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (list != null && list.size() > 0){
                    //listview.smoothScrollToPosition(0);
                    //listview.scrollToPosition(0);
                    myScrollView.scrollTo(0,0);
                }
            }
        });
        updateTitle();
        avi = rootBinding.avi;
        myClipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
        if (list == null){
            list = new ArrayList<DryCommentModel>();
        }
        if (nameList == null){
            nameList = new ArrayList<String>();
            nameList.add("分享给微信好友");
            nameList.add("分享到微信朋友圈");
            nameList.add("分享给QQ好友");
            nameList.add("分享到QQ空间");
            nameList.add("分享到微博");
        }
        if (moreList == null){
            moreList = new ArrayList<String>();
        }
        initCommentSource();
        initComment();
        registerBoradcastReceiver();
    }

    private void updateTitle(){
        if (way == 1){
            int count = Integer.valueOf(dryCommentModel.getCcount()) + dryCommentModel.getReplycount();
            if (count > 0){
                topbar.getTitleView().setText(count+"条回复");
            }else {
                topbar.getTitleView().setText("评论回复");
            }
        }
    }

    private void onClickCopy(String text){
        try{
            ClipData myClip = ClipData.newPlainText("text", text);
            myClipboard.setPrimaryClip(myClip);
            Toast.makeText(getApplicationContext(), "内容已复制~",
                    Toast.LENGTH_SHORT).show();
        }catch (Exception e){

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (isReply == true){
            isReply = false;
            if (CommonUtils.isLogin() == true){
                replyCommentModel = dryCommentModel;
                uid = dryCommentModel.getUserid();
                commentId = dryCommentModel.getCommentid();
                replyName = dryCommentModel.getNickname();
                replyContent = dryCommentModel.getContent();
                replyComment();
            }
        }
        if (isShare == true){
            isShare = false;
            commentShare(-1);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mBroadcastReceiver);
    }

    private void initCommentSource(){
        rootBinding.commonItem.drycommentListviewItemReply.setVisibility(View.VISIBLE);
        CommonItemViewController controller = new CommonItemViewController(rootBinding.commonItem);
        TextView content = rootBinding.commonItem.drycommentListviewItemContent;
        content.setClickable(true);
        content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                replyCommentModel = dryCommentModel;
                uid = dryCommentModel.getUserid();
                commentId = dryCommentModel.getCommentid();
                replyName = dryCommentModel.getNickname();
                replyContent = dryCommentModel.getContent();
                replyComment();
            }
        });
        controller.setModel(dryCommentModel, -1, new CommonItemViewController.EventDispatcher() {
            @Override
            public void onComment(Integer index) {
                if (!checkLogin()) {
                    return;
                }
                commentUser(index);
            }

            @Override
            public void onMoreAction(Integer index) {
                if (!checkLogin()) {
                    return;
                }
                commentMore(index);
            }

            @Override
            public void onReplay(Integer index) {
                /*
                replyCommentModel = dryCommentModel;
                uid = dryCommentModel.getUserid();
                commentId = dryCommentModel.getCommentid();
                replyName = dryCommentModel.getNickname();
                replyContent = dryCommentModel.getContent();
                replyComment();
                */
                fromSource(dryCommentModel);
            }

            @Override
            public void onActionLike(Integer index) {
                if (!checkLogin()) {
                    return;
                }
                commentLike(index);
            }

            @Override
            public void onActionCollect(Integer index) {
                if (!checkLogin()) {
                    return;
                }
                commentCollect(index);
            }

            private boolean checkLogin() {
                boolean login = CommonUtils.isLogin();
                if (!login){
                    Intent intent = new Intent(LangCommentActivity.this,LoginActivity.class);
                    startActivity(intent);
                }
                return login;
            }
        });
        TextView replyText = rootBinding.commonItem.replyText;
        replyText.setText("查看原内容");

        comment_reply_bt = rootBinding.commentReplyBt;
        comment_reply_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (CommonUtils.isLogin() == false){
                    Intent intent = new Intent(LangCommentActivity.this,LoginActivity.class);
                    startActivity(intent);
                    return;
                }
                replyCommentModel = dryCommentModel;
                uid = dryCommentModel.getUserid();
                commentId = dryCommentModel.getCommentid();
                replyName = dryCommentModel.getNickname();
                replyContent = dryCommentModel.getContent();
                replyComment();
            }
        });

        ImageView lang_member_icon = controller.getBinding().langMemberIcon;
        if (!CommonUtils.isEmpty(dryCommentModel.getMemberIcon())){
            lang_member_icon.setVisibility(View.VISIBLE);
            if (LangCommentActivity.this != null){
                try{
                    Glide.with(LangCommentActivity.this).load(dryCommentModel.getMemberIcon()).
                            diskCacheStrategy(DiskCacheStrategy.RESOURCE).fitCenter().centerCrop().into(lang_member_icon);
                }catch (Exception e){
                    LangPublishActivity.uploadError("每日推荐加载图片报错："+e.getLocalizedMessage());
                }
            }
        }else {
            lang_member_icon.setVisibility(View.INVISIBLE);
        }

    }

    /**
     * 点击了返回导航按钮
     */
    @Override
    public void onBackClick() {
        finish();
    }

    /**
     * 点击了右边导航按钮
     */
    @Override
    public void onRightClick() {

    }

    private void  initComment(){
        listview=(RecyclerView) findViewById(R.id.comment_listview);
        //LinearLayoutManager layoutManager = new LinearLayoutManager(LangCommentActivity.this);
        LinearLayoutManager layoutManager = new LinearLayoutManager(LangCommentActivity.this, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        listview.setLayoutManager(layoutManager);
        listview.setHasFixedSize(false);
        listview.setNestedScrollingEnabled(false);
        ((DefaultItemAnimator) listview.getItemAnimator()).setSupportsChangeAnimations(false);//解决局部更新闪烁问题
        adapter=new CommentRecyclerAdapter();
        listview.setAdapter(adapter);

        /*
        listview.setDivider(new ColorDrawable(AppThemeUtils.getInstance().getBackgroundColor()));

        listview.setDividerHeight((int)(1* ScreenUtils.getScreenDensity(CustomApplication.mContext)));

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.e("TAG","position="+position);
                int index = position;// - 1;
                while (index < 0){//解决部分手机点击第一条不是从1开始的问题
                    index+=1;
                }

                commentMore(index);
            }
        });
        */

        mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
        //设置 Header 为 贝塞尔雷达 样式
        mRefreshLayout.setRefreshHeader(new BezierRadarHeader(LangCommentActivity.this).setEnableHorizontalDrag(true));//BezierRadarHeader
        //设置 Footer 为 球脉冲 样式
        mRefreshLayout.setRefreshFooter(new ClassicsFooter(LangCommentActivity.this).setSpinnerStyle(SpinnerStyle.FixedBehind));//BallPulseFooter ClassicsFooter
        mRefreshLayout.setPrimaryColors(AppThemeUtils.getInstance().getRefreshBackgroundColor(),AppThemeUtils.getInstance().getRefreshAccessColor());
        mRefreshLayout.setEnableRefresh(true);//启用刷新
        mRefreshLayout.setEnableLoadMore(true);//启用加载
        //刷新
        mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                //refreshlayout.finishRefresh();
                getLatest();
            }
        });
        mRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                //refreshLayout.finishLoadMore();
                loadMore();
            }
        });

        /*
        //这里一定不能漏掉
        listview.setPullLoadEnable(false);
        listview.setPullRefreshEnable(true);

        listview.setXListViewListener(new XListView.IXListViewListener() {

            @Override
            public void onRefresh() {
                adapter.notifyDataSetChanged();
                SimpleDateFormat sdf = new SimpleDateFormat(
                        "yyyy-MM-dd HH:mm:ss");
                Date date = new Date(System.currentTimeMillis());
                listview.setRefreshTime(sdf.format(date));
                getLatest();

            }

            @Override
            public void onLoadMore() {
                loadMore();
            }
        });
        */


        getLatest();
    }

    private void getLatest(){
        pageIndex = 0;
        new Thread(){
            @Override
            public void run() {
                super.run();
                final Map<String,String> map = new HashMap<String, String>();
                map.put("pageIndex",pageIndex+"");
                map.put("pageRecord",Records+"");
                if (CommonUtils.isLogin() == true){
                    map.put("token",CustomApplication.loginModel.getToken());
                }
                String url = "miniapp/"+"langappid"+"/commentrelylist.do";
                if (type == 1){
                    map.put("dataId",dryCommentModel.getCommentid()+"");
                    map.put("dataWay", way+"");
                    url = "weishu/theme/comment/reply/list.do";
                }else {
                    map.put(APIKey.idKey,dryCommentModel.getCommentid()+"");
                    map.put("way", way+"");
                }
                HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
                    @Override
                    public void onSuccess(String data) {
                        Log.e("TAG","评论内容："+data);
                        //listview.stopRefresh(true);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                mRefreshLayout.finishRefresh();
                                CommonModel commonModel = GsonTools.getCommonModel(data);
                                if (commonModel.getFlag().equals("1")){
                                    list.clear();
                                    List<DryCommentModel> l = GsonTools.getDryCommentModel1(data);
                                    if (l != null && l.size() > 0){
                                        Log.e("TAG","评论内容大小="+l.size());
                                        if (l.size() > 10){
                                            //listview.setPullLoadEnable(true);
                                            mRefreshLayout.setEnableLoadMore(true);
                                        }else {
                                            //listview.setPullLoadEnable(false);
                                            mRefreshLayout.setEnableLoadMore(false);
                                        }
                                        list.addAll(l);
                                    }else {
                                        //listview.setPullLoadEnable(false);
                                        mRefreshLayout.setEnableLoadMore(false);
                                    }
                                    adapter.notifyDataSetChanged();
                                    pageIndex += 1;
                                }else {
                                    CustomApplication.showTip(commonModel, LangCommentActivity.this);
                                }
                            }
                        });
                    }

                    @Override
                    public void onError(String msg) {
                        //listview.stopRefresh(true);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                mRefreshLayout.finishRefresh();
                            }
                        });
                    }
                });
            }
        }.start();

    }

    private void loadMore(){

        new Thread(){
            @Override
            public void run() {
                super.run();
                final Map<String,String> map = new HashMap<String, String>();
                map.put("pageIndex",pageIndex+"");
                map.put("pageRecord",Records+"");
                if (CommonUtils.isLogin() == true){
                    map.put("token",CustomApplication.loginModel.getToken());
                }
                String url = "miniapp/"+"langappid"+"/commentrelylist.do";
                if (type == 1){
                    map.put("dataId",dryCommentModel.getCommentid()+"");
                    map.put("dataWay", way+"");
                    url = "weishu/theme/comment/reply/list.do";
                }else {
                    map.put(APIKey.idKey,dryCommentModel.getCommentid()+"");
                    map.put("way", way+"");
                }
                HttpsUtils.miniAppDo(map, url,  new HttpCallBack() {
                    @Override
                    public void onSuccess(String data) {
                        //listview.stopLoadMore();
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                mRefreshLayout.finishLoadMore();
                                CommonModel commonModel = GsonTools.getCommonModel(data);
                                if (commonModel.getFlag().equals("1")){
                                    pageIndex += 1;
                                    List<DryCommentModel> l = GsonTools.getDryCommentModel1(data);
                                    int fromposition = list.size();
                                    if (l != null && l.size() > 0){
                                        if (l.size() > 0){
                                            //listview.setPullLoadEnable(true);
                                            mRefreshLayout.setEnableLoadMore(true);
                                        }else {
                                            //listview.setPullLoadEnable(false);
                                            mRefreshLayout.setEnableLoadMore(false);
                                        }
                                        list.addAll(l);
                                    }else {
                                        ToastUtil.show(LangCommentActivity.this, "亲，我是有底线的~");
                                        //listview.setPullLoadEnable(false);
                                        mRefreshLayout.setEnableLoadMore(false);
                                    }
                                    if (l != null){
                                        adapter.notifyItemRangeChanged(fromposition, l.size());
                                    }
                                }else {
                                    CustomApplication.showTip(commonModel, LangCommentActivity.this);
                                }
                            }
                        });
                    }

                    @Override
                    public void onError(String msg) {
                        //listview.stopLoadMore();
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                mRefreshLayout.finishLoadMore();
                            }
                        });
                    }
                });
            }
        }.start();
    }

    private void replyComment(){

        if (CommonUtils.bindMobile(LangCommentActivity.this) == true){
            return;
        }

        dialog = new KeyMapDailog("回复@"+replyCommentModel.getNickname(), new KeyMapDailog.SendBackListener() {
            @Override
            public void sendBack(final String inputText) {
                if (inputText == null || inputText.length() == 0){
                    return;
                }
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //dialog.hideProgressdialog();
                        dialog.dismiss();
                        avi.show();

                        new Thread(){
                            @Override
                            public void run() {
                                super.run();
                                String url = "miniapp/"+"langappid"+"/langcl.do";
                                final HashMap<String, String> map = new HashMap<String, String>();
                                if (type == 1){
                                    url = "weishu/theme/comment.do";
                                    map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
                                    map.put("dataId", id);
                                    map.put("dataUserId",uid);
                                    map.put("dataType","2");
                                    map.put("dataContent",inputText);
                                    map.put("dataAnswerId",replyCommentModel.getCommentid());
                                }else {
                                    map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
                                    map.put("id", id);
                                    map.put("uid",uid);
                                    map.put(APIKey.typeKey,"2");
                                    map.put(APIKey.contentKey,inputText);
                                    map.put("answerid",replyCommentModel.getCommentid());
                                }
                                Log.e("TAG", "评论参数="+map+"\n");

                                HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
                                    @Override
                                    public void onSuccess(String data) {
                                        Log.e("TAG","评论结果："+data);
                                        final CommonModel commonModel = GsonTools.getCommonModel(data);
                                        if (commonModel.getFlag().equals("1")){
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    avi.hide();
                                                    ToastUtil.show(LangCommentActivity.this, "回复成功");
                                                    DryCommentModel model = new DryCommentModel();
                                                    model.setContent(inputText);
                                                    model.setUserid(CustomApplication.loginModel.getUid());
                                                    model.setHeader(CustomApplication.loginModel.getHeader());
                                                    model.setNickname(CustomApplication.loginModel.getNickname());
                                                    model.setTime(System.currentTimeMillis()+"");
                                                    model.setCcount("0");
                                                    model.setLcount("0");
                                                    model.setIslike("0");
                                                    model.setSharecount("0");
                                                    model.setCollectcount("0");
                                                    model.setIscollect("0");
                                                    model.setType("0");
                                                    model.setSourceid(id);
                                                    model.setCommentid(commonModel.getData()+"");
                                                    double v = Double.valueOf(model.getCommentid());
                                                    int n = (int)v;
                                                    model.setCommentid(n+"");
                                                    if (uid.equals(model.getUserid())){
                                                        model.setType("0");
                                                        Log.e("TAG","评论id="+model.getCommentid()+"\n");
                                                    }else {
                                                        model.setType("2");
                                                        model.setReplyContent(replyContent);
                                                        model.setReplyid(uid);
                                                        model.setReplynickname(replyName);
                                                        Log.e("TAG",uid+"评论id="+model.getCommentid()+"\n");
                                                    }
                                                    model.setOrderid(replyCommentModel.getOrderid()+1);
                                                    model.setReplyid(replyCommentModel.getUserid());
                                                    model.setReplynickname(replyCommentModel.getNickname());
                                                    if (way == 1){
                                                        dryCommentModel.setReplycount(dryCommentModel.getReplycount()+1);
                                                        updateTitle();
                                                    }
                                                    uid = model.getUserid();
                                                    list.add(0,model);
                                                    //adapter.notifyDataSetChanged();
                                                    //adapter.notifyItemInserted(0);
                                                    if (list.size() > 1){
                                                        myScrollView.scrollTo(0, 0);
                                                    }
                                                    adapter.notifyDataSetChanged();
                                                }
                                            });
                                        }else {
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    avi.hide();
                                                    ToastUtil.show(LangCommentActivity.this, "提交失败");
                                                }
                                            });
                                        }
                                    }

                                    @Override
                                    public void onError(String msg) {
                                        runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                avi.hide();
                                                ToastUtil.show(LangCommentActivity.this, "提交失败");
                                            }
                                        });
                                    }
                                });
                            }
                        }.start();
                    }
                }, 10);
            }
        });
        dialog.show(getSupportFragmentManager(), "dialog");
    }

    /*
    private class MyAdapter extends BaseAdapter implements CommonItemViewController.EventDispatcher {

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return list.size();
        }


        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public boolean isEnabled(int position) {
            // TODO Auto-generated method stub
            return super.isEnabled(position);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            //convertView的复用
            CommonItemViewController controller = null;
            if (convertView != null) {
                controller = (CommonItemViewController) convertView.getTag(R.layout.drycomment_listview_item);
            }
            if (controller == null) {
                controller = new CommonItemViewController(LangCommentActivity.this, R.layout.drycomment_listview_item, parent);
                controller.getBinding().getRoot().setTag(R.layout.drycomment_listview_item, controller);
            }
            DryCommentModel model = list.get(position);
            controller.setModel(model, position, this);
            TextView content =  controller.getBinding().drycommentListviewItemContent;
            if (model.getOrderid() - dryCommentModel.getOrderid() > 1){
                String ss1 = "回复";
                String ss2 = "@"+model.getReplynickname();
                String ss3 = ":"+model.getContent();
                content.setHighlightColor(getResources().getColor(android.R.color.transparent));
                SpannableString spanableInfo = new SpannableString(ss1+ss2+ss3);
                spanableInfo.setSpan(new Clickable(userClickListener),ss1.length(),ss1.length()+ss2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                content.setText(spanableInfo);
                content.setMovementMethod(LinkMovementMethod.getInstance());
            }

            TextView reply_text = controller.getBinding().replyText;


            content = controller.getBinding().drycommentListviewItemContent;
            content.setClickable(true);
            content.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int index = (int)view.getTag();
                    commentMore(index);
                }
            });
            TextView replycount_text = controller.getBinding().replycountText;
            RelativeLayout drycomment_listview_item_reply = controller.getBinding().drycommentListviewItemReply;
            if (way == 1){
                drycomment_listview_item_reply.setVisibility(View.GONE);
                replycount_text.setVisibility(View.GONE);
            }else {
                drycomment_listview_item_reply.setVisibility(View.VISIBLE);
                replycount_text.setVisibility(View.GONE);
            }


            return controller.getBinding().getRoot();
        }

        @Override
        public void onComment(Integer index) {
            commentUser(index);
        }

        @Override
        public void onMoreAction(Integer index) {
            commentMore(index);
        }

        @Override
        public void onReplay(Integer index) {
            commentReply(index, true);
        }

        @Override
        public void onActionLike(Integer index) {
            commentLike(index);
        }

        @Override
        public void onActionCollect(Integer index) {
            commentCollect(index);
        }
    }
    */

    //点击了评论用户
    private void commentUser(final int index){
        DryCommentModel iModel = null;
        if (index == -1){
            iModel = dryCommentModel;
        }else {
            if (list == null || list.size() == 0){
                return;
            }
            iModel = list.get(index);
        }
        final DryCommentModel model = iModel;
        //进入个人主页
        Intent intent = new Intent(LangCommentActivity.this, UserLangActivity.class);
        intent.putExtra(APIKey.useridKey,model.getUserid());
        intent.putExtra(APIKey.typeKey,1);
        intent.putExtra(APIKey.titleKey,model.getNickname());
        startActivity(intent);
    }

    //评论点击更多
    private void commentMore(final int index){
        DryCommentModel iModel = null;
        if (index == -1){
            iModel = dryCommentModel;
        }else {
            if (list == null || list.size() == 0){
                return;
            }
            iModel = list.get(index);
        }
        final DryCommentModel model = iModel;
        opIndex = index;
        moreList.clear();
        moreList.add("回复");
        if (model.getIslike().equals("0")){
            moreList.add("笔芯");
        }
        if (model.getIscollect().equals("0")){
            moreList.add("收藏");
        }
        moreList.add("复制");
        if (CommonUtils.isLogin() == true){
            if (CustomApplication.loginModel.getUid().equals(model.getUserid()) || CustomApplication.loginModel.getUid().equals(dryCommentModel.getUserid())){
                moreList.add("删除");
            }
        }
        //moreList.add("来源");
        moreList.add("举报");

        ActionSheetDialog actionSheetDialog = new ActionSheetDialog(LangCommentActivity.this)
                .builder()
                .setTitle("请选择")
                .setCancelable(false)
                .setCanceledOnTouchOutside(true);
        for (String s : moreList){
            actionSheetDialog.addSheetItem(s, null, new ActionSheetDialog.OnSheetItemClickListener() {
                @Override
                public void onClick(int which) {
                    if (which > 0){
                        String title = moreList.get(which-1);
                        if (title.equals("回复")){
                            commentReply(index,true);
                        }else if (title.equals("笔芯")){
                            commentLike(index);
                        }else if (title.equals("收藏")){
                            commentCollect(index);
                        }else if (title.equals("删除")){
                            CustomDialog dialog = null;
                            final CustomDialog.Builder builder = new CustomDialog.Builder(LangCommentActivity.this);
                            builder.setTitle("温馨提示");
                            builder.setMessage("确定要删除？");
                            builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    commentDelete(index);
                                }
                            });
                            builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                            dialog = builder.create();
                            dialog.show();
                        }else if (title.equals("复制")){
                            onClickCopy(model.getContent());
                        }else if (title.equals("举报")){
                            report(model.getCommentid(), 3);
                        }else if (title.equals("来源")){
                            fromSource(model);
                        }
                    }
                }
            });
        }
        actionSheetDialog.show();
    }

    //评论点击了笔芯
    private void commentLike(final int index){

        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(LangCommentActivity.this,LoginActivity.class);
            startActivity(intent);
            return;
        }
        DryCommentModel iModel = null;
        if (index == -1){
            iModel = dryCommentModel;
        }else {
            if (list == null || list.size() == 0){
                return;
            }
            iModel = list.get(index);
        }
        final DryCommentModel model = iModel;
        if(CommonUtils.isEmpty(model.getCommentid())){
            return;
        }
        if (model.getIslike().equals("1")){
            if (index == -1){
                int count = Integer.valueOf(dryCommentModel.getLcount());
                if (count > 0){
                    count -= 1;
                }
                dryCommentModel.setLcount(count+"");
                dryCommentModel.setIslike("0");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        rootBinding.commonItem.langLikeImg.setImageResource(R.drawable.workgroup_img_like);
                        rootBinding.commonItem.langLikeText.setTextColor(AppThemeUtils.getInstance().getSmallTextColor());
                    }
                });
            }else {
                int count = Integer.valueOf(model.getLcount());
                if (count > 0){
                    count -= 1;
                }
                model.setLcount(count+"");
                model.setIslike("0");
                list.set(index,model);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //adapter.notifyDataSetChanged();
                        adapter.notifyItemChanged(index);
                    }
                });
            }
        }else {
            if (index == -1){
                int count = Integer.valueOf(dryCommentModel.getLcount());
                count += 1;
                dryCommentModel.setLcount(count+"");
                dryCommentModel.setIslike("1");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        rootBinding.commonItem.langLikeImg.setImageResource(R.drawable.workgroup_img_like_sel);
                        rootBinding.commonItem.langLikeText.setTextColor(ContextCompat.getColor(LangCommentActivity.this,R.color.lightGreenColor));
                    }
                });
            }else {
                int count = Integer.valueOf(model.getLcount());
                count += 1;
                model.setLcount(count+"");
                model.setIslike("1");
                list.set(index,model);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //adapter.notifyDataSetChanged();
                        adapter.notifyItemChanged(index);
                    }
                });
            }
        }

        final Map<String,String> map = new HashMap<String, String>();
        map.put(APIKey.tokenKey,CustomApplication.loginModel.getToken());
        map.put(APIKey.idKey,model.getCommentid());
        String url = "miniapp/"+"langappid"+"/langlikecomment.do";
        if (type == 1){
            url = "weishu/theme/comment/like.do";
        }
        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
            @Override
            public void onSuccess(String data) {
            }

            @Override
            public void onError(String msg) {

            }
        });
    }

    //评论收藏
    private void commentCollect(final int index){
        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(LangCommentActivity.this,LoginActivity.class);
            startActivity(intent);
            return;
        }

        DryCommentModel iModel = null;
        if (index == -1){
            iModel = dryCommentModel;
        }else {
            if (list == null || list.size() == 0){
                return;
            }
            iModel = list.get(index);
        }
        final DryCommentModel model = iModel;
        if(CommonUtils.isEmpty(model.getCommentid())){
            return;
        }
        if (model.getIscollect().equals("1")){
            if (index == -1){
                int count = Integer.valueOf(dryCommentModel.getCollectcount());
                if (count > 0){
                    count -= 1;
                }
                dryCommentModel.setCollectcount(count+"");
                dryCommentModel.setIscollect("0");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        rootBinding.commonItem.langCollectImg.setImageResource(R.drawable.collection);
                        rootBinding.commonItem.langCollectText.setTextColor(AppThemeUtils.getInstance().getSmallTextColor());
                    }
                });
            }else {
                model.setIscollect("0");
                model.setCollectcount(Integer.valueOf(model.getCollectcount())-1+"");
                //adapter.notifyDataSetChanged();
                adapter.notifyItemChanged(index);
            }
        }else {
            if (index == -1){
                int count = Integer.valueOf(dryCommentModel.getCollectcount());
                count += 1;
                dryCommentModel.setCollectcount(count+"");
                dryCommentModel.setIscollect("1");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        rootBinding.commonItem.langCollectImg.setImageResource(R.drawable.collection_sel);
                        rootBinding.commonItem.langCollectText.setTextColor(ContextCompat.getColor(LangCommentActivity.this,R.color.lightGreenColor));
                    }
                });
            }else {
                model.setIscollect("1");
                model.setCollectcount(Integer.valueOf(model.getCollectcount())+1+"");
                //adapter.notifyDataSetChanged();
                adapter.notifyItemChanged(index);
            }
        }

        final HashMap<String, String> map = new HashMap<String, String>();
        map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
        map.put("sourceid", model.getCommentid());
        map.put(APIKey.typeKey,"0");
        if (type == 1){
            map.put(APIKey.typeKey,"3");
        }
        String url = "miniapp/"+"langappid"+"/addcollection.do";
        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
            @Override
            public void onSuccess(String data) {
                Log.e("TAG","收藏结果："+data);
            }

            @Override
            public void onError(String msg) {
            }
        });
    }

    //评论删除
    private void commentDelete(final int index){
        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(LangCommentActivity.this,LoginActivity.class);
            startActivity(intent);
            return;
        }
        DryCommentModel iModel = null;
        if (index == -1){
           iModel = dryCommentModel;
        }else {
            if (list == null || list.size() == 0){
                return;
            }
            iModel = list.get(index);
        }
        final DryCommentModel model = iModel;
        if(CommonUtils.isEmpty(model.getCommentid())){
            return;
        }
        final HashMap<String, String> map = new HashMap<String, String>();
        map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
        map.put("id", model.getCommentid());
        map.put(APIKey.typeKey,"0");
        String url = "miniapp/"+"langappid"+"/deletecomment.do";
        if (type == 1){
            url = "weishu/theme/comment/delete.do";
        }
        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
            @Override
            public void onSuccess(String data) {
                Log.e("TAG","删除结果："+data);
                avi.hide();
                CommonModel commonModel = GsonTools.getCommonModel(data);
                if (commonModel.getFlag().equals("1")){
                    if (index == -1){
                        finish();
                    }else {
                        list.remove(model);
                        if (way == 1){
                            if (dryCommentModel.getReplycount() > 0){
                                dryCommentModel.setReplycount(dryCommentModel.getReplycount()-1);
                                updateTitle();
                            }
                        }
                        adapter.notifyDataSetChanged();
                    }
                }else {
                    CustomApplication.showTip(commonModel, LangCommentActivity.this);
                }
            }

            @Override
            public void onError(String msg) {
                avi.hide();
            }
        });
    }

    //评论分享
    private void commentShare(final int index){
        DryCommentModel iModel = null;
        if (index == -1){
            iModel = dryCommentModel;
        }else {
            if (list == null || list.size() == 0){
                return;
            }
            iModel =  list.get(index);
        }
        final DryCommentModel model = iModel;
        opIndex = index;

        final ShareDialog shareDialog = new ShareDialog(LangCommentActivity.this)
                .builder()
                .setCancelable(false)
                .setCanceledOnTouchOutside(true);
        shareDialog.friend_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dialog.dismiss();
                //分享到朋友圈
                shareToWX(0,model.getContent());
            }
        });
        shareDialog.wx_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dialog.dismiss();
                //分享给微信好友
                shareToWX(1,model.getContent());
            }
        });
        shareDialog.wb_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dialog.dismiss();
                //微博
                CustomApplication.WbShareType = 0;
                CustomApplication.WbShareSourceId = model.getCommentid();
                CustomApplication.WbShareText = model.getContent();;
                Intent mIntent = new Intent(BroadcastDefine.WeiBo_Share_Action);
                //发送广播
                sendBroadcast(mIntent);
            }
        });
        shareDialog.qq_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dialog.dismiss();
                //分享到qq
                shareToQQ(0,model.getContent(),"【微句评论】");
            }
        });
        shareDialog.zone_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareDialog.dialog.dismiss();
                //qq空间
                shareToQQ(1,model.getContent(),"【微句评论】");
            }
        });
        shareDialog.show();

        /*
        ActionSheetDialog actionSheetDialog = new ActionSheetDialog(LangCommentActivity.this)
                .builder()
                .setTitle("请选择")
                .setCancelable(false)
                .setCanceledOnTouchOutside(true);
        for (String s : nameList){
            actionSheetDialog.addSheetItem(s, null, new ActionSheetDialog.OnSheetItemClickListener() {
                @Override
                public void onClick(int which) {
                    if (which == 1){
                        //分享给微信好友
                        shareToWX(1,model.getContent());
                    }else if (which == 2){
                        //分享到朋友圈
                        shareToWX(0,model.getContent());
                    }else if (which == 3){
                        //分享到qq
                        shareToQQ(0,"【微句评论】",model.getContent());
                    }else if (which == 4){
                        //qq空间
                        shareToQQ(0,"【微句评论】",model.getContent());
                    }else if (which == 5){
                        //微博
                        CustomApplication.WbShareType = 0;
                        CustomApplication.WbShareSourceId = model.getCommentid();
                        CustomApplication.WbShareText = model.getContent();;
                        Intent mIntent = new Intent(BroadcastDefine.WeiBo_Share_Action);
                        //发送广播
                        sendBroadcast(mIntent);
                    }
                }
            });
        }
        actionSheetDialog.show();
        */
    }

    //评论回复
    private void commentReply(final int index, boolean isReply){
        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(LangCommentActivity.this,LoginActivity.class);
            startActivity(intent);
            return;
        }
        if (index == -1){
            replyCommentModel = dryCommentModel;
            uid = dryCommentModel.getUserid();
            commentId = dryCommentModel.getCommentid();
            replyName = dryCommentModel.getNickname();
            replyContent = dryCommentModel.getContent();
            replyComment();
            return;
        }
        if (list == null || list.size() == 0){
            return;
        }
        DryCommentModel model = list.get(index);
        if (way == 1){
            replyCommentModel = model;
            uid = model.getUserid();
            commentId = model.getCommentid();
            replyName = model.getNickname();
            replyContent = model.getContent();
            replyComment();
        }else {
            if (!CommonUtils.isEmpty(model.getCommentid())){
                Intent intent = new Intent(LangCommentActivity.this,LangCommentActivity.class);
                intent.putExtra("id",model.getSourceid());
                intent.putExtra("type",type);
                Bundle bundle = new Bundle();
                bundle.putSerializable("DryCommentModel", model);
                intent.putExtras(bundle);
                intent.putExtra("isReply",isReply);
                startActivity(intent);
            }
        }
    }


    private MyIUiListener mIUiListener = new MyIUiListener();
    class MyIUiListener implements IUiListener {
        @Override
        public void onComplete(Object o) {
            Log.e("TAG","分享成功");
            getShareGold();
        }

        @Override
        public void onError(UiError uiError) {
            Log.e("TAG","分享出错");
        }

        @Override
        public void onCancel() {
            Log.e("TAG","分享取消");
        }

        @Override
        public void onWarning(int i) {

        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Tencent.onActivityResultData(requestCode, resultCode, data, mIUiListener);
        if (requestCode == Constants.REQUEST_API) {
            if (resultCode == Constants.REQUEST_QQ_SHARE || resultCode == Constants.REQUEST_QZONE_SHARE || resultCode == Constants.REQUEST_OLD_SHARE) {
                Tencent.handleResultData(data, mIUiListener);
            }
        }
    }

    private void getShareGold(){
        DryCommentModel iModel = null;
        if (opIndex == -1){
            iModel = dryCommentModel;
        }else {
            if (list == null || list.size() == 0){
                return;
            }
            iModel = list.get(opIndex);
        }
        final DryCommentModel model = iModel;
        model.setSharecount(Integer.valueOf(model.getSharecount())+1+"");
        final HashMap<String, String> map = new HashMap<String, String>();
        map.put(APIKey.tokenKey, CustomApplication.loginModel.getToken());
        map.put("id", model.getCommentid());
        String url = "miniapp/"+"langappid"+"/langsharecomment.do";
        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
            @Override
            public void onSuccess(final String data) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        avi.hide();
                        final CommonModel commonModel = GsonTools.getCommonModel(data);
                        if (commonModel.getFlag().equals("1")){
                            new Handler().postDelayed(new Runnable(){
                                public void run() {
                                    adapter.notifyDataSetChanged();
                                }
                            }, 10);
                        }else {
                            CustomApplication.showTip(commonModel, LangCommentActivity.this);
                        }
                    }
                });
            }

            @Override
            public void onError(String msg) {
                avi.hide();
            }
        });
    }

    /**
     * 广播接收者
     * @author Gordon
     */
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver(){
        @Override
        public void onReceive(Context context, Intent intent) {
            System.out.print("onReceive接收到广播了" + "\n");
            String action = intent.getAction();
            if (action.equals(BroadcastDefine.WX_Share_Result)){

                //这个方法分享无效
//                Message msg = new Message();
//                msg.obj = new String(HandlerDefine.wx_share_result);
//                myHandler.sendMessage(msg);
                getShareGold();
            }
        }
    };
    /**
     * 注册广播
     * @author Gordon
     */
    public void registerBoradcastReceiver(){
        IntentFilter myIntentFilter = new IntentFilter();
        //添加接收广播类型
        myIntentFilter.addAction(BroadcastDefine.WX_Share_Result);
        //注册广播
        registerReceiver(mBroadcastReceiver, myIntentFilter);
    }

    //分享文字到微信
    private void shareToWX(int type, String title){

        WXTextObject textObject = new WXTextObject();
        textObject.text = title;

        WXMediaMessage msg = new WXMediaMessage();
        msg.mediaObject = textObject;
        msg.description = title;

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = buildTransaction("text");
        req.message = msg;
        req.scene = type==0 ? SendMessageToWX.Req.WXSceneTimeline:SendMessageToWX.Req.WXSceneSession;
        CustomApplication.mWxApi.sendReq(req);

    }
    private String buildTransaction(final String type) {
        return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
    }

    //分享到qq
    private Bundle params;
    private void shareToQQ(int type,String title,String content){
        params = new Bundle();
        if (type == 0){//分享给QQ好友
            params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
            params.putString(QQShare.SHARE_TO_QQ_TITLE, title);// 标题
            params.putString(QQShare.SHARE_TO_QQ_SUMMARY, content);// 摘要
            params.putString(QQShare.SHARE_TO_QQ_TARGET_URL,"http://a.app.qq.com/o/simple.jsp?pkgname=com.zhongshengnetwork.rightbe");// 内容地址
            params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL,"http://image.daydayrise.net/360@2x.png");// 网络图片地址
            params.putString(QQShare.SHARE_TO_QQ_EXT_INT, "");//其它附加功能
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    CustomApplication.mTencent.shareToQQ(LangCommentActivity.this, params, mIUiListener);
                }
            });
        }else {
            //分享到QQ空间
            params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE,QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT);
            params.putString(QzoneShare.SHARE_TO_QQ_TITLE, title);// 标题
            params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, content);// 摘要
            params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL,"http://a.app.qq.com/o/simple.jsp?pkgname=com.zhongshengnetwork.rightbe");// 内容地址
            ArrayList<String> imgUrlList = new ArrayList<>();
            imgUrlList.add("http://image.daydayrise.net/360@2x.png");
            params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL,imgUrlList);// 图片地址
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    CustomApplication.mTencent.shareToQzone(LangCommentActivity.this, params, mIUiListener);
                }
            });
        }

    }

    private void report(String reportId, int reportType){//reportType:1-举报人；2-举报微句；3-举报评论
        if (CommonUtils.isLogin() == false){
            Intent intent = new Intent(LangCommentActivity.this,LoginActivity.class);
            startActivity(intent);
            return;
        }
        Intent intent = new Intent(LangCommentActivity.this, ReportActivity.class);
        intent.putExtra(APIKey.idKey,reportId);
        intent.putExtra(APIKey.typeKey,reportType);
        startActivity(intent);
    }

    private void fromSource(DryCommentModel model){
        if (type == 1){//微纸条相关
            if (model.getSourceid().length() == 32){
                dealWithWZTContent(model.getSourceid());
            }else {
                dealWithWZT(model.getSourceid(),1);
            }
        }else {//微句
            final HashMap<String, String> map = new HashMap<String, String>();
            map.put(APIKey.idKey, model.getSourceid());
            if (CommonUtils.isLogin() == true){
                map.put(APIKey.tokenKey,CustomApplication.loginModel.getToken());
            }
            String url = "miniapp/langappid/getlanginfo.do";
            HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
                @Override
                public void onSuccess(String data) {
                    avi.hide();
                    CommonModel commonModel = GsonTools.getCommonModel(data);
                    if (commonModel.getFlag().equals("1")){
                        LangInfoModel langInfoModel = GsonTools.getLangInfoModel(data);
                        if (langInfoModel.getStatus() == 1){
                            Intent intent = new Intent(LangCommentActivity.this, LangDetailActivity.class);
                            Bundle bundle=new Bundle();
                            bundle.putSerializable("model", langInfoModel);//序列化
                            intent.putExtras(bundle);//发送数据
                            intent.putExtra("share",false);
                            startActivity(intent);
                        }
                    }else {
                        CustomApplication.showTip(commonModel, LangCommentActivity.this);
                    }
                }

                @Override
                public void onError(String msg) {
                    avi.hide();
                }
            });
        }
    }

    private void dealWithWZT(String id, final int selectIndex){
        final HashMap<String, String> map = new HashMap<String, String>();
        map.put(APIKey.idKey, id);
        if (CommonUtils.isLogin() == true){
            map.put(APIKey.tokenKey,CustomApplication.loginModel.getToken());
        }
        String url = "weishu/theme/info.do";
        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
            @Override
            public void onSuccess(String data) {
                CommonModel commonModel = GsonTools.getCommonModel(data);
                if (commonModel.getFlag().equals("1")){
                    WeiShuInfoDetailModel langInfoModel = GsonTools.getWeiShuInfo(data);

                    if (CommonUtils.isLogin() == true && CustomApplication.loginModel.getUid().equals(langInfoModel.getUserid())){
                        Intent intent = new Intent(LangCommentActivity.this, WZTActivity.class);
                        Bundle bundle=new Bundle();
                        bundle.putSerializable("model", langInfoModel);//序列化
                        intent.putExtras(bundle);//发送数据
                        intent.putExtra("selectIndex",selectIndex);
                        startActivity(intent);
                    }else {
                        WZTUtils.goToWZT(LangCommentActivity.this,langInfoModel);
                    }
                }else {
                    CustomApplication.showTip(commonModel, LangCommentActivity.this);
                }
            }

            @Override
            public void onError(String msg) {
            }
        });
    }

    private void dealWithWZTContent(String langid){
        final HashMap<String, String> map = new HashMap<String, String>();
        map.put(APIKey.idKey, langid);
        if (CommonUtils.isLogin() == true){
            map.put(APIKey.tokenKey,CustomApplication.loginModel.getToken());
        }
        String url = "weishu/content/info.do";
        HttpsUtils.miniAppDo(map, url, new HttpCallBack() {
            @Override
            public void onSuccess(String data) {
                CommonModel commonModel = GsonTools.getCommonModel(data);
                if (commonModel.getFlag().equals("1")){
                    WeiShuContentDetailModel langInfoModel = GsonTools.getWeiShuContentDetailModel(data);
                    Intent intent = new Intent(LangCommentActivity.this, WZTContentActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putSerializable("model", langInfoModel);//序列化
                    intent.putExtras(bundle);//发送数据
                    startActivity(intent);
                }else {
                    CustomApplication.showTip(commonModel, LangCommentActivity.this);
                }
            }

            @Override
            public void onError(String msg) {
            }
        });
    }


    private View.OnClickListener userClickListener=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Toast.makeText(LifeCommentListActivity.this, v.getTag()+"点击成功....",Toast.LENGTH_SHORT).show();
            DryCommentModel iModel = list.get((int)v.getTag());
            final DryCommentModel model = iModel;
            //进入个人主页
            Intent intent = new Intent(LangCommentActivity.this, UserLangActivity.class);
            intent.putExtra(APIKey.useridKey,model.getReplyid());
            intent.putExtra(APIKey.typeKey,1);
            intent.putExtra(APIKey.titleKey,model.getReplynickname());
            startActivity(intent);
        }
    };


    class Clickable extends ClickableSpan {
        private final View.OnClickListener mListener;

        public Clickable(View.OnClickListener l) {
            mListener = l;
        }

        /**
         * 重写父类点击事件
         */
        @Override
        public void onClick(View v) {
            mListener.onClick(v);
        }

        /**
         * 重写父类updateDrawState方法  我们可以给TextView设置字体颜色,背景颜色等等...
         */
        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setColor(getResources().getColor(R.color.lightBlueGolor));
        }
    }

    //以下是用的recycleview替代listview提高性能
    private class CommentRecyclerAdapter extends RecyclerView.Adapter<CommentRecyclerAdapter.ViewHolder>{

        public CommentRecyclerAdapter(){

        }

        class ViewHolder extends RecyclerView.ViewHolder{

            private ImageView drycomment_listview_item_header;
            private ImageView drycomment_listview_private_icon;
            private TextView drycomment_listview_item_name;
            private TextView drycomment_listview_item_time;
            private TextView drycomment_listview_item_content;

            private RelativeLayout drycomment_listview_item_reply;
            private TextView reply_text;
            private TextView replycount_text;

            private FrameLayout drycomment_listview_item_more;

            private RelativeLayout lang_like;
            private ImageView lang_like_img;
            private TextView lang_like_text;

            private RelativeLayout lang_collect;
            private ImageView lang_collect_img;
            private TextView lang_collect_text;

            private RelativeLayout comment_layout;
            private LinearLayout item_gas_line;

            private ImageView lang_member_icon;

            public ViewHolder(View view){
                super(view);

                drycomment_listview_item_header = (ImageView) view.findViewById(R.id.drycomment_listview_item_header);
                drycomment_listview_private_icon = (ImageView) view.findViewById(R.id.drycomment_listview_private_icon);
                drycomment_listview_item_name = (TextView) view.findViewById(R.id.drycomment_listview_item_name);
                drycomment_listview_item_time = (TextView) view.findViewById(R.id.drycomment_listview_item_time);
                drycomment_listview_item_content = (TextView) view.findViewById(R.id.drycomment_listview_item_content);

                drycomment_listview_item_reply = (RelativeLayout) view.findViewById(R.id.drycomment_listview_item_reply);
                reply_text = (TextView) view.findViewById(R.id.reply_text);
                replycount_text = (TextView) view.findViewById(R.id.replycount_text);

                drycomment_listview_item_more = (FrameLayout) view.findViewById(R.id.drycomment_listview_item_more);

                lang_like = (RelativeLayout) view.findViewById(R.id.lang_like);
                lang_like_img = (ImageView) view.findViewById(R.id.lang_like_img);
                lang_like_text = (TextView) view.findViewById(R.id.lang_like_text);

                lang_collect = (RelativeLayout) view.findViewById(R.id.lang_collect);
                lang_collect_img = (ImageView) view.findViewById(R.id.lang_collect_img);
                lang_collect_text = (TextView) view.findViewById(R.id.lang_collect_text);

                comment_layout = (RelativeLayout) view.findViewById(R.id.comment_layout);

                item_gas_line = (LinearLayout) view.findViewById(R.id.item_gas_line);

                lang_member_icon = (ImageView) view.findViewById(R.id.lang_member_icon);

            }

        }


        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_listview_item,parent,false);
            ViewHolder holder = new ViewHolder(view);
            return holder;
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position)
        {
            Log.e("TAG", "position="+position);
            DryCommentModel model = list.get(position);

            holder.comment_layout.setBackgroundColor(AppThemeUtils.getInstance().getMainColor());
            holder.comment_layout.setTag(position);
            holder.comment_layout.setClickable(true);
            holder.comment_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    commentMore((Integer) view.getTag());
                }
            });
            holder.item_gas_line.setBackgroundColor(AppThemeUtils.getInstance().getBackgroundColor());

            holder.drycomment_listview_item_header.setClickable(true);
            holder.drycomment_listview_item_header.setTag(position);
            holder.drycomment_listview_item_header.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    commentUser((Integer) v.getTag());
                }
            });

            holder.drycomment_listview_private_icon.setClickable(true);
            holder.drycomment_listview_private_icon.setTag(position);
            holder.drycomment_listview_private_icon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    commentUser((Integer) v.getTag());
                }
            });

            holder.drycomment_listview_item_name.setClickable(true);
            holder.drycomment_listview_item_name.setTag(position);
            holder.drycomment_listview_item_name.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    commentUser((Integer) v.getTag());
                }
            });

            holder.drycomment_listview_item_more.setClickable(true);
            holder.drycomment_listview_item_more.setTag(position);
            holder.drycomment_listview_item_more.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    commentMore((Integer) v.getTag());
                }
            });

            holder.drycomment_listview_item_reply.setBackgroundResource(AppThemeUtils.getInstance().getCommentButtonBackground());
            holder.drycomment_listview_item_reply.setClickable(true);
            holder.drycomment_listview_item_reply.setTag(position);
            holder.drycomment_listview_item_reply.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    commentReply((Integer) v.getTag(), true);
                }
            });


            holder.reply_text.setText("回复");

            holder.replycount_text.setTag(position);
            int count = Integer.valueOf(model.getCcount());// + model.getReplycount();
            if (count > 0){
                holder.replycount_text.setVisibility(View.VISIBLE);
                holder.replycount_text.setText("查看"+count+"条回复 >");
            }else {
                holder.replycount_text.setVisibility(View.INVISIBLE);
            }
            holder.replycount_text.setClickable(true);
            holder.replycount_text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    commentReply((int)view.getTag(), false);
                }
            });
            if (way == 1){
                holder.drycomment_listview_item_reply.setVisibility(View.GONE);
                holder.replycount_text.setVisibility(View.GONE);
            }else {
                holder.drycomment_listview_item_reply.setVisibility(View.VISIBLE);
                holder.replycount_text.setVisibility(View.GONE);
            }

            holder.lang_like.setVisibility(View.VISIBLE);
            holder.lang_like.setTag(position);
            holder.lang_like.setFocusable(false);
            holder.lang_like.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    commentLike((Integer) v.getTag());
                }
            });

            if (model.getIslike().equals("1")){
                holder.lang_like_img.setImageResource(R.drawable.workgroup_img_like_sel);
                holder.lang_like_text.setTextColor(ContextCompat.getColor(LangCommentActivity.this,R.color.lightGreenColor));
            }else {
                holder.lang_like_img.setImageResource(R.drawable.workgroup_img_like);
                holder.lang_like_text.setTextColor(AppThemeUtils.getInstance().getSmallTextColor());
            }
            if (ConvertUtility.parseInt(model.getLcount()) < 1) {
                holder.lang_like_text.setText("笔芯");
            } else {
                holder.lang_like_text.setText(model.getLcount());
            }

            holder.lang_collect.setVisibility(View.VISIBLE);
            holder.lang_collect.setTag(position);
            holder.lang_collect.setFocusable(false);
            holder.lang_collect.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    commentCollect((Integer) v.getTag());
                }
            });
            ImageView collect_icon = holder.lang_collect_img;
            TextView collect_count = holder.lang_collect_text;
            if (model.getIscollect().equals("1")){
                collect_icon.setImageResource(R.drawable.collection_sel);
                collect_count.setTextColor(ContextCompat.getColor(LangCommentActivity.this,R.color.lightGreenColor));
            }else {
                collect_icon.setImageResource(R.drawable.collection);
                collect_count.setTextColor(AppThemeUtils.getInstance().getSmallTextColor());
            }
            collect_count.setText(ConvertUtility.parseInt(model.getCollectcount()) < 1 ? "收藏" : model.getCollectcount());

            Glide.with(LangCommentActivity.this).load(model.getHeader()).transform(new CircleTransform(LangCommentActivity.this)).dontAnimate().into(holder.drycomment_listview_item_header);
            if (!CommonUtils.isEmpty(model.getPrivateIcon())){
                holder.drycomment_listview_private_icon.setVisibility(View.VISIBLE);
                Glide.with(LangCommentActivity.this).load(model.getPrivateIcon()).transform(new CircleTransform(LangCommentActivity.this)).dontAnimate().into(holder.drycomment_listview_private_icon);
            }else {
                holder.drycomment_listview_private_icon.setVisibility(View.INVISIBLE);
            }

            String lcount = CommonUtils.getDisplayCount(Integer.valueOf(model.getLcount()));
            String s1 = DateUtil.getChatDate(Long.valueOf(model.getTime()))+"";
            holder.drycomment_listview_item_time.setText(s1);
            holder.drycomment_listview_item_time.setTextColor(AppThemeUtils.getInstance().getSmallTextColor());

            holder.drycomment_listview_item_time.setTag(position);
            holder.drycomment_listview_item_time.setFocusable(false);


            holder.drycomment_listview_item_name.setText(model.getNickname());
            holder.drycomment_listview_item_content.setTag(position);
            holder.drycomment_listview_item_content.setText(model.getContent());
            holder.drycomment_listview_item_content.setFocusable(false);
            if (model.getOrderid() - dryCommentModel.getOrderid() > 1){
                String ss1 = "回复";
                String ss2 = "@"+model.getReplynickname();
                String ss3 = ":"+model.getContent();
                holder.drycomment_listview_item_content.setHighlightColor(getResources().getColor(android.R.color.transparent));
                SpannableString spanableInfo = new SpannableString(ss1+ss2+ss3);
                spanableInfo.setSpan(new Clickable(userClickListener),ss1.length(),ss1.length()+ss2.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                holder.drycomment_listview_item_content.setText(spanableInfo);
                holder.drycomment_listview_item_content.setMovementMethod(LinkMovementMethod.getInstance());
            }

            holder.drycomment_listview_item_name.setTextColor(AppThemeUtils.getInstance().getUserNameColorOfWeiJu());
            holder.drycomment_listview_item_content.setTextColor(AppThemeUtils.getInstance().getTextColorOfWeiJu());
            holder.drycomment_listview_item_content.setTag(position);
            holder.drycomment_listview_item_content.setClickable(true);
            holder.drycomment_listview_item_content.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    commentMore((Integer) view.getTag());
                }
            });

            if (!CommonUtils.isEmpty(model.getMemberIcon())){
                holder.lang_member_icon.setVisibility(View.VISIBLE);
                if (LangCommentActivity.this != null){
                    try{
                        Glide.with(LangCommentActivity.this).load(model.getMemberIcon()).
                                diskCacheStrategy(DiskCacheStrategy.RESOURCE).fitCenter().centerCrop().into(holder.lang_member_icon);
                    }catch (Exception e){
                        LangPublishActivity.uploadError("评论回复列表加载图片报错："+e.getLocalizedMessage());
                    }
                }
            }else {
                holder.lang_member_icon.setVisibility(View.INVISIBLE);
            }

        }

        @Override
        public int getItemCount() {
            return list.size();
        }
    }


}
